<?php
use mdm\admin\components\MenuHelper;
use backend\models\AuthAssignment;
?>
<aside class="main-sidebar">

    <section class="sidebar">

        <!-- Sidebar user panel -->
        <div class="user-panel">
            <div class="pull-left image">
                <img src="<?php //= $directoryAsset ?>/images/logo.png" class="img-circle" alt="User Image"/>
            </div>
            <div class="pull-left info">
                <p><?=Yii::$app->user->identity->realname ? Yii::$app->user->identity->realname : Yii::$app->user->identity->username ?></p>
<?php  $role = AuthAssignment::find()->where(['user_id'=>Yii::$app->user->id])->One();
    $myrole = empty($role) ? '未分配' :$role->item_name;
?>
                <a href="#"><i class="fa fa-circle text-success"></i> <?=$myrole?></a>
            </div>
        </div>

        <!-- search form -->
        <form action="/goods/index" method="get" class="sidebar-form">
            <div class="input-group">
                <input type="text" name="GoodsSearch[goodsname]" class="form-control" placeholder="Search..."/>
              <span class="input-group-btn">
                <button type='submit' name='search' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i>
                </button>
              </span>
            </div>
        </form>
        <!-- /.search form -->
<?php
$callback = function($menu){
    $data = json_decode($menu['data'], true);
    $items = $menu['children'];
    $return = [
        'label' => $menu['name'],
        'url' => [$menu['route']],
    ];
    //处理我们的配置
    if ($data) {
        //visible
        isset($data['visible']) && $return['visible'] = $data['visible'];
        //icon
        isset($data['icon']) && $data['icon'] && $return['icon'] = $data['icon'];
        //url
        isset($data['url']) && $data['url'] && $return['url'] = $data['url'];
        //other attribute e.g. class...
        $return['options'] = $data;
    }
    //没配置图标的显示默认图标，默认图标大家可以自己随便修改
    (!isset($return['icon']) || !$return['icon']) && $return['icon'] = 'circle-o';
    $items && $return['items'] = $items;

    return $return;
};

echo dmstr\widgets\Menu::widget( [
    'options' => ['class' => 'sidebar-menu'],
    'items' => MenuHelper::getAssignedMenu(Yii::$app->user->id,null,$callback),
] );
?>
        <?php //echo  dmstr\widgets\Menu::widget(

//            [
//                'options' => ['class' => 'sidebar-menu tree', 'data-widget'=> 'tree'],
//                'items' => [
//                    ['label' => '商品', 'icon' => 'shopping-cart', 'url' => ['/goods'],
//                        'items'=>[
//                                ['label'=>'商品列表','icon'=>'list','url'=>'/goods/index'],
//                            ['label'=>'添加商品','icon'=>'plus','url'=>'/goods/create'],
//                            ['label'=>'商品审核','icon'=>'check','url'=>'/goods/auth'],
//                            ['label'=>'商品分类列表','icon'=>'check','url'=>'/goods-class/index'],
//
//                        ]],
//                    ['label' => '账号', 'icon' => 'user', 'url' => ['/admin/user'],
//                        'items'=>[
//                            ['label'=>'用户列表','icon'=>'user-circle','url'=>'/admin/user'],
//                            ['label'=>'添加用户','icon'=>'user-plus','url'=>'/user/add'],
//
//                        ]
//                        ],
//                    [
//                        'label' => '权限',
//                        'icon' => 'fa fa-circle-o',
//                        'url' => 'javascript:;',
//                        'items' => [
//                            ['label' => '路由管理', 'icon' => 'share-alt', 'url' => '/admin/route'],
//                            ['label' => '权限管理', 'icon' => 'fa fa-circle-o', 'url' => '/admin/permission'],
//                            ['label' => '角色列表', 'icon' => 'user', 'url' => '/admin/role'],
//                            ['label' => '用户与角色', 'icon' => 'user-circle', 'url' => '/admin/assignment'],
//                            ['label' => '菜单管理', 'icon' => 'file-image-o', 'url' => '/admin/menu'],
//                        ],
//                    ],
//                    ['label' => 'Menu Yii2', 'options' => ['class' => 'header']],
//
//                    ['label' => '设置', 'icon' => 'gear', 'url' => ['/setting'],
//                        'items'=>[
//                            ['label'=>'供应商列表','icon'=>'check','url'=>'/gys/index'],
//                            ['label'=>'店铺列表','icon'=>'check','url'=>'/shop/index'],
//
//                        ]],
////                    ['label' => 'debug', 'icon' => 'dashboard', 'url' => ['/debug']],
////                    ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
//                    [
//                        'label' => 'Some tools',
//                        'icon' => 'share',
//                        'url' => '#',
//                        'items' => [
//                            ['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii'],],
//                            ['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug'],],
//                            [
//                                'label' => 'Level One',
//                                'icon' => 'circle-o',
//                                'url' => '#',
//                                'items' => [
//                                    ['label' => 'Level Two', 'icon' => 'circle-o', 'url' => '#',],
//                                    [
//                                        'label' => 'Level Two',
//                                        'icon' => 'circle-o',
//                                        'url' => '#',
//                                        'items' => [
//                                            ['label' => 'Level Three', 'icon' => 'circle-o', 'url' => '#',],
//                                            ['label' => 'Level Three', 'icon' => 'circle-o', 'url' => '#',],
//                                        ],
//                                    ],
//                                ],
//                            ],
//                        ],
//                    ],
//                ],
//            ]
       // ) ?>

    </section>

</aside>
